package newcoder.huawei.lx_HJ5_进制转换;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @author Mr.wang
 * @date 2021/11/12
 */
public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String str;
        while ((str = reader.readLine()) != null) {
            String substring = str.substring(2);
            int sum = 0;
            int length = substring.length();
            for (int i = length - 1; i >= 0; i--) {
                int tempNum = substring.charAt(i);
                if (tempNum >= 65) {
                    tempNum = tempNum - 65 + 10;
                } else {
                    tempNum = tempNum - 48;
                }
                sum = sum + (int) Math.pow(16, length - i - 1) * tempNum;
            }
            System.out.println(sum);
        }
    }
}
